package net.hn.hnms.config;

import net.hn.hnms.entity.Config;
import net.hn.hnms.entity.FtpConfig;
import net.hn.hnms.job.ScheduleRunnalbe;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * 智呈物联 pan'sx
 * 2023/10/23 11:16
 * 1.0 version
 */
@Component
public class CommandLineRunnerImpl implements CommandLineRunner {
    @Autowired
    private Config config;


    @Autowired
    private CronTaskRegistrar cronTaskRegistrar;
    @Override
    public void run(String... args) {
        for (FtpConfig ftpConfig:config.getList()){
            if("cron".equals(ftpConfig.getMode())) {
                ScheduleRunnalbe scheduledTask = new ScheduleRunnalbe(ftpConfig);
                cronTaskRegistrar.addTask(scheduledTask, ftpConfig.getCron());
            }else if("listen".equals(ftpConfig.getMode())){
                ScheduleRunnalbe scheduledTask = new ScheduleRunnalbe(ftpConfig);
                scheduledTask.run();
            }
        }
    }
}
